import Vue from "vue"
import { mapState, mapMutations } from "vuex"
import { randomString, debounce } from "./index"
import { baseImgUrl } from "../service/config.js"
import request from '../api/request'
Vue.mixin({
    data() {
        return {
            $imgurl: baseImgUrl,
            headbg: {
                backgroundImage: 'linear-gradient(-90deg, #B90C08, #FF6600, #FFC200)',
            },
            ptop: {
                paddingTop: (2 * this.nav_height) + 'px'
            },
            randomString,
            API:request.API,
            BaseURL:request.BaseURL,
            qfapp:request.qfapp
        }
    },
    computed: {
        ...mapState([
            // 丰苗
            "schoolInfo",
            'userInfo',
            'allPermission',
            'supplierList', //供应商
            'detailData',
            'nav_height'
        ]),
    },
    methods: {
        debounce,
        clearCode() {
            uni.login({
                success: res => {
                    uni.setStorageSync("logincode", res.code);
                },
                fail: err => {
                    uni.setStorageSync("logincode", '');
                }
            })
        },
        checkDone(callback) {
            if (uni.getStorageSync("applyShenglueOpenid") && uni.getStorageSync("applyShenglueSession_key") && uni.getStorageSync("shenglueApplytoken")) {
                // 已经登录
                callback()
            } else {
                // 没有授权
                // this.changexShow(true);   // 挑起弹框  
                this.$refs.mlogin.confirm();
                return false;
            }
        },
        getRanNum() {
            return 100 + Math.floor(Math.random() * 400);
        },
        ...mapMutations([
            // 丰苗
            'setDetailData',
            "getSchoolInfo",
            'getUserInfo',
            'getAllpermission',
            'getSupplierList',//供应商列表
            'setNavHeight'
        ]),
        gotoHome() {
            uni.switchTab({
                url: '../home/home'
            })
        },
        checkIsLoginToken() {
            if (uni.getStorageSync("applyShenglueOpenid") && uni.getStorageSync("applyShenglueSession_key") && uni.getStorageSync("shenglueApplytoken")) {
                this.$refs.mlogin.show = false;
            } else {
                this.$refs.mlogin.show = true;
            }
        },
        gotothispage(url) {
            uni.navigateTo({
                url
            })
        }
    },
    mounted() {

    },
})